package com.blog.module.photos.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.common.mybatis.Page;
import com.blog.common.mybatis.ParsePagination;
import com.blog.module.photos.mapper.PhotosMapper;
import com.blog.module.photos.pojo.Photos;
import com.blog.module.photos.pojo.PhotosExample;

@Service
public class PhotosService {

	@Autowired
	private PhotosMapper photosMapper;

	public Page pagePhotos(Photos photos) {
		ParsePagination pagination = new ParsePagination();
		int pageNo = pagination.getPageNo();
		int pageSize = pagination.getPageSize();
		PhotosExample example = new PhotosExample();
		if (photos != null) {
			example.createCriteria().andTitleEqualTo(photos.getTitle());
		}
		int count = photosMapper.countByExample(example);
		List<Photos> list = new ArrayList<Photos>();
		Page page = new Page(count, pageNo, pageSize, list);
		example.setLimitStart((pageNo - 1) * pageSize);
		example.setLimitEnd(pageSize);
		list = photosMapper.selectByExample(example);
		page.setList(list);
		return page;
	}

	public int update(Photos photos) {
		return photosMapper.updateByPrimaryKeySelective(photos);
	}

	public Photos selectById(int id) {
		return photosMapper.selectByPrimaryKey(id);
	}
	public List<Photos> selectPhotosList() {
		PhotosExample example = new PhotosExample();
		return photosMapper.selectByExample(example);
	}
	public int insert(Photos photos) {
		return photosMapper.insert(photos);
	}
}
